package com.haitaoit.chengquan.module.car.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.car.model.CarModel;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/10/25.
 */
public class OrderSubmitAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<CarModel> list;

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public OrderSubmitAdapter(Context context) {
        this.context = context;
    }

    public List<CarModel> getList() {
        return list;
    }

    public void setList(List<CarModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.car_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.car_cb.setVisibility(View.GONE);
        holder.car_line.setVisibility(View.VISIBLE);
        holder.car_jian.setVisibility(View.GONE);
        holder.car_jia.setVisibility(View.GONE);

        ImageLoader.getInstance().displayImage(list.get(position).getImg_url(), holder.car_img);
        holder.car_title.setText(list.get(position).getTitle());
        holder.car_spec.setText("规格：" + list.get(position).getSpecifications());
        holder.car_price.setText("¥ " + list.get(position).getPrice());
        holder.car_num.setText(list.get(position).getCount() + "件");
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.car_cb)
        CheckBox car_cb;
        @ViewInject(R.id.car_line)
        View car_line;
        @ViewInject(R.id.car_jian)
        ImageView car_jian;
        @ViewInject(R.id.car_jia)
        ImageView car_jia;
        @ViewInject(R.id.car_img)
        ImageView car_img;
        @ViewInject(R.id.car_title)
        TextView car_title;
        @ViewInject(R.id.car_spec)
        TextView car_spec;
        @ViewInject(R.id.car_price)
        TextView car_price;
        @ViewInject(R.id.car_num)
        TextView car_num;
    }
}
